package map;

import java.awt.*;
import java.awt.event.*;
import java.awt.Canvas;
import java.awt.Graphics;

public class Monitor implements ActionListener{
    private MapColor mc;
    private Polygon[] p;
    private TextField text;
    private Checkbox cbx;
    private int[][] metrix;
    public Monitor(MapColor mc,Polygon[] p,TextField text,Checkbox cbx,int[][] metrix){
        this.mc=mc;
        this.p=p;
        this.text=text;
        this.cbx=cbx;
        this.metrix=metrix;
    }
    public void actionPerformed(ActionEvent event){
        Object obj = event.getSource();
        Button btn = (Button)obj;
        if(btn.getLabel().equals("TraceBack")){
            Util util = new Util(mc,p,cbx,metrix);
            long startTime=System.currentTimeMillis();   //获取开始时间
            util.backtrack();
            long endTime=System.currentTimeMillis(); //获取结束时间
            text.setText((endTime-startTime)+"ms");
        }
        else if(btn.getLabel().equals("Optimize")){
            UtilOptimize utilOpt = new UtilOptimize(mc,p,cbx,metrix);
            long startTime=System.currentTimeMillis();   //获取开始时间
            utilOpt.optimize();
            long endTime=System.currentTimeMillis(); //获取结束时间
            text.setText((endTime-startTime)+"ms");
        }
        else{
            Util util = new Util(mc,p,cbx,metrix);
            util.resetMap();
            text.setText(null);
            cbx.setState(false);
        }
    }
}
